Golang flag.Uint() function example
package flag
Uint defines a uint flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a uint variable that stores the value of the flag.
Golang flag.Uint() function usage example
package main
import (
"flag"
"fmt"
"strconv"
)
func main() {
port := flag.Uint("port", 8080, "Port to listen. Default is 8080")
flag.Parse()
fmt.Println(flag.Lookup("port")) // print the Flag struct
fmt.Printf("Port number is %s\n ", strconv.Itoa(int(*port)))
}
Output :
&{port Port to listen. Default is 8080 8080 8080}
Port number is 8080
Reference :
Advertisement
Something interesting
Tutorials
+7.5k Golang : Handling Yes No Quit query input
+6.1k Golang : Debug with Godebug
+18.1k Golang : Check if a directory exist or not
+5.2k Golang : Issue HTTP commands to server and port example
+19.2k Golang : Delete item from slice based on index/key position
+10.6k Golang : Select region of interest with mouse click and crop from image
+15.2k Golang : Get HTTP protocol version example
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+6.9k Fix sudo yum hang problem with no output or error messages
+7k Golang : Gargish-English language translator
+13.7k Golang : Check if an integer is negative or positive
+14.5k Golang : Find network of an IP address